/*
 * MacIntegration.java
 * 
 * Created on Oct 29, 2007, 9:49:06 AM
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package procrastinator.mac;


import com.apple.eawt.Application;
import com.apple.eawt.ApplicationEvent;
import com.apple.eawt.ApplicationListener;
import procrastinator.Main;

public class MacIntegration {
	public static boolean isMac() {
		return System.getProperty("mrj.version") != null;
	}
	
	public static void integrate() {
		if( isMac() ) {
			System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Procrastinator");
			System.setProperty("apple.laf.useScreenMenuBar", "true");
			
			Application app = Application.getApplication();

			app.addAboutMenuItem();
			app.setEnabledAboutMenu(true);
			
			app.addPreferencesMenuItem();
			app.setEnabledPreferencesMenu(true);
			
			app.addApplicationListener(new UtoolApplicationListener());
			
		}
	}
	
	private static class UtoolApplicationListener implements ApplicationListener {
		
		public void handleAbout(ApplicationEvent e) {
                    Main.getApplication().getMainWindow().showAboutBox(null);
			e.setHandled(true);
		}


		public void handlePreferences(ApplicationEvent e) {
		}
		

		public void handleQuit(ApplicationEvent e) {
                    Main.getApplication().quit(null);
			e.setHandled(true);
		}

		public void handleOpenApplication(ApplicationEvent event) {
			// TODO Auto-generated method stub
			
		}

		public void handlePrintFile(ApplicationEvent event) {
			// TODO Auto-generated method stub
			
		}

		public void handleReOpenApplication(ApplicationEvent event) {
			// TODO Auto-generated method stub
			
		}

		public void handleOpenFile(ApplicationEvent event) {
			// TODO Auto-generated method stub
			
		}
	}
	
}
